package com.xukehong.frame.controller;

import com.xukehong.frame.security.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Optional;

/**
 * @author 许克弘
 * @date 2020/2/29 22:34
 */
@Controller
@RequestMapping
@Slf4j
@Api(tags = "登录")
public class LoginController {



    @ApiOperation("默认登录地址")
    @GetMapping("/")
    public String defaultLogin() {
        log.info("进入登录");
        return "login";
    }

    @ApiOperation("登录地址")
    @GetMapping("/login")
    public String login() {
        log.info("进入登录");
        return "login";
    }

    @ApiOperation("登录成功跳转地址")
    @PostMapping("/index")
    public String index(){
        Optional<String> username = SecurityUtils.getCurrentUserLogin();
        String role = SecurityUtils.getCurrentUserRole();
        log.info("用户:"+username.get()+"--角色:"+role);
        //根据角色查询登录后的菜单列表等


        return "index";
    }

}
